package com.example.appforphysician.fragment;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.appforphysician.AddScheduleActivity;
import com.example.appforphysician.ManagerActivity;
import com.example.appforphysician.R;
import com.example.appforphysician.adapter.ServiceConnector;

public class FragmentSchedule extends Fragment {
	private LayoutInflater inflaterPtr;

	public static Fragment newInstance(Context context) {
		FragmentSchedule f = new FragmentSchedule();

		return f;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		inflaterPtr = inflater;
		ViewGroup root = (ViewGroup) inflater.inflate(
				R.layout.fragment_schedule, null);
		ListView list = (ListView) root.findViewById(R.id.lvSchedule);

		ArrayList<HashMap<String, String>> mylist = ServiceConnector
				.getSingleton().getPhysicianSchedule().printAdapter();

		SimpleAdapter mSchedule = new SimpleAdapter(getActivity()
				.getApplicationContext(), mylist,
				R.layout.item_listview_schedule, new String[] { "PatientID",
						"PatientName", "PatientDate", "PatientTime",
						"PatientService", "PatientAddress" }, new int[] {
						R.id.tv_sche_patientID, R.id.tv_sche_patientName,
						R.id.tv_sche_patientDate, R.id.tv_sche_patientTime,
						R.id.tv_sche_patientService,
						R.id.tv_sche_patientAddress });

		list.setAdapter(mSchedule);

		Button btnAddSchedule = (Button) root.findViewById(R.id.btnAddSchedule);
		btnAddSchedule.setOnClickListener(btnAddScheduleClickListener);

		return root;
	}

	private View.OnClickListener btnAddScheduleClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			ViewGroup root = (ViewGroup) inflaterPtr.inflate(
					R.layout.fragment_schedule, null);
			Intent intent = new Intent(getActivity().getApplicationContext(),
					AddScheduleActivity.class);
			startActivity(intent);
		}
	};

}